package com.zhs.demoutil.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zhs.demoutil.dao.TableRecordDao;
import com.zhs.demoutil.entity.ExportCheckResult;
import com.zhs.demoutil.entity.TableRecord;
import com.zhs.demoutil.entity.TmpCheckResult;
import com.zhs.demoutil.service.TableRecordService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.util.Assert;

import java.rmi.server.ExportException;
import java.util.List;

@Service
@Slf4j
public class TableRecordServiceImpl extends ServiceImpl<TableRecordDao, TableRecord> implements TableRecordService {
    @Override
    public Page<ExportCheckResult> pageNoCheckResult(Long tableId, Integer current, Integer size, String street) {
        Page<ExportCheckResult> tablePage = new Page<>(current, size);
        TableRecord tableRecord = getById(tableId);
        Assert.notNull(tableRecord,"数据不存在");
        String tableName = tableRecord.getTableName();
        Long count = baseMapper.count(tableName,street);
        int offset = (current-1)*size;
        List<ExportCheckResult> list = baseMapper.list(tableName, Math.max(offset, 0),size,street);
        tablePage.setRecords(list);
        tablePage.setTotal(count);
        return tablePage;
    }
}
